<?php
	add_filter('manage_store_posts_columns', 'admin_count_coupon_header_columns', 10, 1);
	add_action('manage_store_posts_custom_column', 'admin_count_coupon_data_row', 10, 2);

	function admin_count_coupon_header_columns($columns)
	{
		if (!isset($columns['total_coupon']))
			$columns['total_coupon'] = "Total coupons";

		return $columns;
	}

	function admin_count_coupon_data_row($column_name, $post_id)
	{	   
		switch ($column_name)
		{
			case 'total_coupon':
				
                global $wpdb;
                $qr = "
                SELECT COUNT(ID) AS 'total' FROM {$wpdb->posts} 
                WHERE ID IN 
                (SELECT post_id FROM {$wpdb->postmeta} WHERE (meta_key = 'store_coupon_metadata' AND meta_value = {$post_id})) "
                ;
                $rs = $wpdb->get_results($qr);
                echo $rs[0]->total;
				break;

			default:
				break;
		}
	}
